package com.appsindy.common.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.appsindy.common.json.JSONResultCommon;
import com.appsindy.reserv.bo.ReserveItem;
import com.appsindy.reserv.service.ReservationServices;
import com.appsindy.reserv.vo.CustomerVO;
import com.appsindy.reserv.vo.ReservePrintReceiptVO;
import com.opensymphony.xwork2.Action;


public class ReservePrintReceiptAction extends AppsindyBaseAction {
	
	private static final long serialVersionUID = 1L;
	
	private int servicePaymentId;
	private int customerId;
	private Date printDate;

	private ReservationServices reservationServices;
	
	private ReservePrintReceiptVO reservePrintReceiptVO;
	
	private CustomerVO customerVO;
	
	private List<CustomerVO> customerList;
	
    private Map<Object, Object> reportParams;
	private List<ReserveItem> listReport;
	
	public String execute() {
		log.info("Init Reservation Print Receipt ...");

		return initialReserve();
	}
	
	private String initialReserve(){
		log.info("Initial Reservation Print Receipt ...");
		setCustomerList(getReservationServices().getCustomerPaymentCombos(servicePaymentId));
		setPrintDate(new Date());
		
		return SUCCESS;
	}
	
	public String print(){
		log.info("Print Reserve Receipt ... Start");
		if(reservePrintReceiptVO != null){
			ReservePrintReceiptVO resultVO = getReservationServices().genAndPrintReceiptPayment(reservePrintReceiptVO);
            if(resultVO != null){
	            /*this.setReportParams(new HashMap<Object, Object>());
	            this.getReportParams().put("receiptCustName", StringUtils.toString(resultVO.getCustomerName()));
	            this.getReportParams().put("receiptCustAddress", StringUtils.toString(resultVO.getAddress()));
	            this.getReportParams().put("printDate", StringUtils.toString(resultVO.getPrintDate()));
	            this.getReportParams().put("receiptNo", StringUtils.toString(resultVO.getReceiptNo()));
	            this.getReportParams().put("discountAmount", (resultVO.getDiscountAmount()==null?BigDecimal.ZERO:resultVO.getDiscountAmount()));
	            
	            this.setListReport(resultVO.getItemDetail());*/
            	
            	setReservePrintReceiptVO(resultVO);
        		log.info("Print Reserve Receipt ... End");
            }
		}/* else{
            this.setListReport(new ArrayList<ReserveItem>());
        }*/
		//return JASPER_RESULT_PDF;
		return "receiptTemplate";
	}
	
    @SuppressWarnings("finally")
	public String getCustomerJSON() {
        Map<String, String> errorMap = new HashMap<String, String>();
        errorMap.put("errorStr", "Not found customer.");
        JSONResultCommon jsonResultCommon = new JSONResultCommon(Action.ERROR, errorMap);
        try {
            if(customerId > 0){
                CustomerVO customerVO = getReservationServices().getCustomerViewById(servicePaymentId, customerId);

                jsonResultCommon = new JSONResultCommon(Action.SUCCESS, customerVO);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            setJsonModel(jsonResultCommon);
            return JSON_RESULT;
        }
    } 

	public int getServicePaymentId() {
		return servicePaymentId;
	}
	public void setServicePaymentId(int servicePaymentId) {
		this.servicePaymentId = servicePaymentId;
	}

	public int getCustomerId() {
		return customerId;
	}
	public void setCustomerId(int customerId) {
		this.customerId = customerId;
	}

	public Date getPrintDate() {
		return printDate;
	}
	public void setPrintDate(Date printDate) {
		this.printDate = printDate;
	}

	public ReservationServices getReservationServices() {
		return reservationServices;
	}
	public void setReservationServices(ReservationServices reservationServices) {
		this.reservationServices = reservationServices;
	}

	public ReservePrintReceiptVO getReservePrintReceiptVO() {
		return reservePrintReceiptVO;
	}
	public void setReservePrintReceiptVO(ReservePrintReceiptVO reservePrintReceiptVO) {
		this.reservePrintReceiptVO = reservePrintReceiptVO;
	}

	public CustomerVO getCustomerVO() {
		return customerVO;
	}
	public void setCustomerVO(CustomerVO customerVO) {
		this.customerVO = customerVO;
	}

	public List<CustomerVO> getCustomerList() {
		return customerList;
	}
	public void setCustomerList(List<CustomerVO> customerList) {
		this.customerList = customerList;
	}

	public List<ReserveItem> getListReport() {
		return listReport;
	}
	public void setListReport(List<ReserveItem> listReport) {
		this.listReport = listReport;
	}

	public Map<Object, Object> getReportParams() {
		return reportParams;
	}
	public void setReportParams(Map<Object, Object> reportParams) {
		this.reportParams = reportParams;
	}
    
}
